package cn.xianyang.system.service.impl;

import cn.xianyang.basic.mapper.BaseMapper;
import cn.xianyang.basic.query.BaseQuery;
import cn.xianyang.basic.service.impl.BaseServiceImpl;
import cn.xianyang.basic.util.PageList;
import cn.xianyang.system.domain.Systemdictionarytype;
import cn.xianyang.system.mapper.SystemdictionarydetailMapper;
import cn.xianyang.system.service.ISystemdictionarytypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemdictionarytypeServiceImpl extends BaseServiceImpl<Systemdictionarytype> implements ISystemdictionarytypeService {

    @Autowired
    private BaseMapper<Systemdictionarytype> mapper;

    @Autowired
    private SystemdictionarydetailMapper systemdictionarydetailMapper;


    @Override
    public void save(Systemdictionarytype systemdictionarytype) {
        mapper.save(systemdictionarytype);
    }

    @Override
    public void update(Systemdictionarytype systemdictionarytype) {
        mapper.update(systemdictionarytype);
    }

    @Override
    public void removeById(Long id) {
        systemdictionarydetailMapper.deleteByTypeId(id);
        mapper.deleteById(id);
    }

    @Override
    public List<Systemdictionarytype> queryAll() {
        return mapper.loadAll();
    }

    @Override
    public Systemdictionarytype queryById(Long id) {
        return mapper.loadById(id);
    }

    /**
     * 高级查询+分页
     * @param tQuery
     * @return
     */
    @Override
    public PageList<Systemdictionarytype> queryPage(BaseQuery tQuery) {
        Long total = mapper.queryCount(tQuery);
        List<Systemdictionarytype> data = mapper.queryData(tQuery);
        return new PageList<>(total,data);
    }

    @Override
    public void batchRemove(List<Long> ids) {
        for (Long id : ids) {
            systemdictionarydetailMapper.deleteByTypeId(id);
        }
        mapper.batchRemove(ids);
    }
}